<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Mod_user extends CI_Model{

/** Developer Chantra Choeung**/
function updateBook($editUserId,$name,$lable,$price,$dec,$imgs,$shipping){
	$arr = array(
		"post_title"=>$name,
		"label"=>$lable,
		"post_image"=>$imgs,
		"price"=>$price,
		"post_description"=>$dec,
		"shipping"=>$shipping
	);
	$this->db->where("postid",$editUserId);
	$this->db->update("tbl_posting",$arr);
}

function viewOrderBook($limit, $offest){
	$this->db->select("tbl_user_shipping.fullname,tbl_user_shipping.email,tbl_user_shipping.mobile,tbl_order_detail.qty,tbl_order_detail.price,tbl_order_detail.is_get,tbl_order_detail.is_pay,tbl_order_detail.bookName,tbl_order_user.order_user_id,tbl_order_detail.order_detail_id");
	$this->db->from("tbl_order_detail");
	$this->db->join("tbl_order_user","tbl_order_user.order_user_id = tbl_order_detail.order_user_id");
	$this->db->join("tbl_user_shipping","tbl_user_shipping.user_shipping_id = tbl_order_user.user_shipping_id");
	$this->db->limit($limit,$offest);
	$this->db->order_by("tbl_order_detail.is_pay","desc");
	return $this->db->get();

}
function deleteOrderBook($bookOrderId){
	$this->db->where("tbl_order_user.order_user_id",$bookOrderId);
	$this->db->delete("tbl_order_user");

	$this->db->where("tbl_order_detail.order_user_id",$bookOrderId);
	$this->db->delete("tbl_order_detail");

}

function returnOrderBook($id){
	$this->db->set("get",1);
	$this->db->where("orderId",$id);
	$this->db->update("tbl_orders");
}
function noreturnOrderBook($id){
	$this->db->set("get",0);
	$this->db->where("orderId",$id);
	$this->db->update("tbl_orders");
}
function count_table($tbl){
	return $this->db->count_all_results($tbl);

}
function getAllCountry(){
	return $this->db->get("tbl_country");
}

/** End of Developer**/
//Start Neth	
	function users_list(){
       	$this->db->select("*");
		$this->db->from('v_users');
		$this->db->where('isdeleted = 0');
        $query = $this->db->get();
        return $query->result();		
	}
	function fetch_country(){
       	$this->db->select("*");
		$this->db->from('tbl_country');		
        $query = $this->db->get();
        return $query->result();		
	}
	function fetch_userrole(){
       	$this->db->select("*");
		$this->db->from('tbl_role');	
        $query = $this->db->get();
        return $query->result();		
	}
	function addUser($fName,$lName,$email,$phone,$username,$password,$roleid,$countryid,$gender,$status){
		$arr = array(
			'roleid'=>$roleid
			,'firstname'=>$fName
			,'lastname'=>$lName
			,'fullname'=>$fName.' '.$lName
			,'email'=>$email
			,'countryid'=>$countryid
			,'phone_num'=>$phone
			,'username'=>$username
			,'password'=>$password
			,'isdeleted'=>0
			,'gender'=>$gender
			,'status'=>$status
			,'createdate'=>date('Y-m-d'),			
		);
		$this->db->insert("tbl_users",$arr);
	}
	function editUser($arrdata,$userid){			
		$this->db->update('tbl_users',$arrdata);	
		$this->db->where('userid',$userid);			
	}
//End Neth
}
?>